<?php 
include './function.php';


// code只可以用一次,10分钟过期
$code = $_GET['code'];
// $code = '25C014C0278AF65E41598A920AA293C6';

$appid = 101464349;
$appkey = cd349fad610875eee6001d19b9232dc8;
$appurl = 'http://wanglei.itwcb.top/qq';

// Step3：通过Authorization Code获取Access Token

$token_url = 'https://graph.qq.com/oauth2.0/token?grant_type=authorization_code&client_id='.$appid.'&client_secret='.$appkey.'&code='.$code.'&redirect_uri='.$appurl;

// http:\/\/qzapp.qlogo.cn\/qzapp\/101346155\/8B93724956D5EAD2A46E7D5965CB135A\/100

$token_res = https_request($token_url);
// var_dump($token_res);

// $token_res = 'access_token=C3D08B75CD39FEA87442AC1076A792EB&expires_in=7776000&refresh_token=F0C0C792DB8917E3CB32244550CC8AA2';

$data = explode('&', $token_res);
$data = explode('=',$data[0]);
$token = $data[1];
// var_dump($token);

// $token = 'C3D08B75CD39FEA87442AC1076A792EB';

// Step4：使用Access Token来获取用户的OpenID
$openid_url = 'https://graph.qq.com/oauth2.0/me?access_token='.$token;
$open_res = https_request($openid_url);

// var_dump($open_res);

$lpos = strpos($open_res, "(");
$rpos = strrpos($open_res, ")");
$open_res  = substr($open_res, $lpos + 1, $rpos - $lpos -1);
$msg = json_decode($open_res,true);

// var_dump($msg);
$openid = $msg['openid'];

// Step5：使用Access Token以及OpenID来访问和修改用户数据

$userinfo_url = 'https://graph.qq.com/user/get_user_info?access_token='.$token.'&oauth_consumer_key=101346155&openid='.$openid;

$userinfo_res = https_request($userinfo_url);


var_dump($userinfo_res);

// 封装成一个 函数
// return $userinfo_res;









 ?>